const tencentcloud = require("tencentcloud-sdk-nodejs");


const IaiClient = tencentcloud.iai.v20180301.Client;
const models = tencentcloud.iai.v20180301.Models;

const Credential = tencentcloud.common.Credential;
const ClientProfile = tencentcloud.common.ClientProfile;
const HttpProfile = tencentcloud.common.HttpProfile;

let cred = new Credential("AKIDau2tNIiKSKvEQLRQmssjgKjtlLs8IDvM", "MQD0UrsfBPLyXq24pJdfQ7ZQ3QVJq6JE");
let httpProfile = new HttpProfile();
httpProfile.endpoint = "iai.tencentcloudapi.com";
let clientProfile = new ClientProfile();
clientProfile.httpProfile = httpProfile;
let client = new IaiClient(cred, "ap-guangzhou", clientProfile);

let req = new models.DetectFaceRequest();

module.exports = async function imagesResult(image){
	return new Promise((resolve,reject)=>{
		let params = `{"Image":"${image}","NeedFaceAttributes":"1"}`
		req.from_json_string(params);
		
		client.DetectFace(req, function(errMsg, response) {
		
		    if (errMsg) {
		        console.log(errMsg);
				reject(errMsg)
		        return;
		    }
			
		    resolve(response);
		});
	})
	
}
